package com.adayo.memoryfree;

import com.adayo.memoryfree.base.BaseApplication;
import com.adayo.memoryfree.exceptions.BaseExceptionHandler;
import com.adayo.memoryfree.exceptions.LocalFileHandler;
import com.adayo.memoryfree.utils.ActivityStackManager;
import com.adayo.memoryfree.utils.JFileKit;
import com.adayo.memoryfree.utils.JLogKit;
import com.adayo.memoryfree.utils.JToastKit;

import org.xutils.x;

import java.io.File;

public class LocalApplication extends BaseApplication {

	private static LocalApplication instance;
	public static ActivityStackManager sActivityStack;

	public static LocalApplication getInstance() {
		if (instance == null) {
			instance = new LocalApplication();
		}
		return instance;
	}

	@Override
	public void onCreate() {
		super.onCreate();
		instance = this;
		x.Ext.init(this);
		x.Ext.setDebug(true);
		JLogKit.getInstance().setTag("mf-->");
		// Create the APP crash log directory
		File appFolder = new File(JFileKit.getDiskCacheDir(this) + "/log/");
		JFileKit.createFolder(appFolder);
		ActivityStackManager.getInstance().init();
		JToastKit.getInstance().init(this);
		sActivityStack = ActivityStackManager.getInstance();
	}

	@Override
	public BaseExceptionHandler getDefaultUncaughtExceptionHandler() {
		return new LocalFileHandler(applicationContext);
	}
}
